package fr.univ.context.utilities;

import fr.univ.context.utilities.Constants;
import android.content.Context;
import android.content.SharedPreferences;

public class Preferences {
	
	/*
	 * SharedPreferences is provide general framework  
	 * to save and retrieve persistent data in key-pairs 
	 * value of primitives data type.
	 * */
	private SharedPreferences sharedPreferences;
	
	
	public Preferences(Context context) {
		
		sharedPreferences = context.getSharedPreferences("TIME", Context.MODE_PRIVATE);
	}
	
	// Capture frequency
	public void save(String key, int vTime) {
		
	    SharedPreferences.Editor editor = getSharedPreferences().edit();
	    editor.putInt(key, vTime); //put your value
	    editor.commit(); //commits your edits
	}
	
	// Active Dialog or not?
	public void save(String key, boolean flagDialog) {
		
		SharedPreferences.Editor editor = getSharedPreferences().edit();
		editor.putBoolean(key, flagDialog); //put your value
		editor.commit(); //commits your edits
	}
	
	// Returns the preference value if it exists, or defValue (15).
	public int loadTimeSleep() {
		
	    return getSharedPreferences().getInt(Constants.KEY_TIME_SLEEP, 15);
	}
	
	// Returns the preference value if it exists, or defValue (false).
	public boolean loadFlagDialog() {
		
		return getSharedPreferences().getBoolean(Constants.KEY_FLAG_DIALOG, false);
	}
	
	public SharedPreferences getSharedPreferences() {
		
		return sharedPreferences;
	}
}
